<?php
	function redirectTo($page)
	{
		header("location:{$page}");
		exit;	
	}
	
	function pageRedirect ($urlLink, $msgStatus = ""){
	if ($msgStatus != ""){$msgStatus = "msgStatus=".$msgStatus;}	
	echo "<script>window.location='$urlLink".$msgStatus."';</script>";	
	}
	
	function errorMessage($error)
	{
		global $errors;
		$error = "<div style='color:red;  padding:5px; margin:3px;
		font:bold 12px;'>$error</div>";
		$errors .= $error;
		return $errors;
	}
function escapeValue($value)
	{
		if(function_exists("mysql_real_escape_string"))
		{
			if(get_magic_quotes_gpc())
			{
				$value = stripslashes($value);	
			}
			$value = mysql_real_escape_string($value);
		}
		else
		{
			if(!get_magic_quotes_gpc())
			{
				$value = addslashes($value);	
			}
		}
		return $value;
	}
	function getParameter($method, $para,$default=""){
	if ($method == "get"){
		if (isset($_GET[$para])){
			$v = $_GET[$para];	
		}else{
			$v = $default;		
		}		
	}else{
		if (isset($_POST[$para])){
			$v = $_POST[$para];	
		}else{
			$v = $default;		
		}		
	}
	return $v;
	}
	//add current visited
	function pageVisited($page, $menu){
		 if ($page == $menu){
		 	echo 'id="current" ';
		 }
	}
	//find max id
	function maxOfAll($column, $table)
    {
      $sql=("SELECT MAX($column) FROM $table");
	  $result=query($sql);
	  $row=fetch_array($result);
	  return $row[0];
	   
    }
	function maxOfAll1($column, $table)
    {
      $sql=("SELECT MAX($column) FROM $table");
	  $result=mysql_query($sql);
	  $row=mysql_fetch_array($result);
	  return $row[0];
	   
    }
	//find min id
	function minOfAll($column, $table)
    {
      $sql=("SELECT MIN($column) FROM $table");
	  $result=query($sql);
	  $row=fetch_array($result);
	  return $row[0];
	   
    }
	function maxOf($column, $table, $where)
    {
	  $sql=("SELECT MAX(`$column`) FROM `$table` WHERE $where");
	  $result=query($sql);
	  $row=fetch_array($result);
	  return $row[0];
    }
	function minOf($column, $table, $where)
    {
	  $sql=("SELECT MAX(`$column`) FROM `$table` WHERE $where");
	  $result=query($sql);
	  $row=fetch_array($result);
	  return $row[0];
    }
	function countOf($table, $where)
    {
	  $sql=("SELECT COUNT(*) FROM `$table` WHERE $where");
	  $result=query($sql);
	  $row=fetch_array($result);
	  return $row[0];
    }
    
    function countOfAll($table)
    {
	  $sql=("SELECT COUNT(*) FROM $table");
	  $result=mysql_query($sql);
	  $row=mysql_fetch_array($result);
	  return $row[0];
    }
?>
